import tkinter as tk

class appliction(tk.Frame):
    def __init__(self,master=None):
        super().__init__(master)
        self.master=master
        self.creatWidget()

    def creatWidget(self):
        self.c1=tk.Canvas(self.master,bg='pink')
        self.c1.place(relwidth=1,relheight=1)
        self.c1.bind("<Button-1>",self.mouseTest)
        self.c1.bind("<B1-Motion>",self.mouseDrag)
        self.master.bind("<KeyPress>",self.keyPress)
        self.master.bind("<KeyPress-a>",self.keyPressa)
        self.master.bind('<KeyRelease-a>',self.keyReleasea)

    def mouseDrag(self,event):
        x=event.x
        y=event.y
        self.c1.create_line(x,y,x+2,y+2)

    def mouseTest(self,event):
        x_root=event.x_root
        y_root=event.y_root
        x=event.x
        y=event.y
        print("坐标(屏幕) x={} y={}".format(x_root,y_root))
        print("坐标(组件内) x={} y={}".format(x,y))

    def keyPress(self,event):
        print('keycode={},char={},keysym={}'.format(event.keycode,event.char,event.keysym))

    def keyPressa(self,event):
        print("key press a")

    def keyReleasea(self,event):
        print("key Release a")

window=tk.Tk()
window.geometry('1000x500')
window.title("时间测试")
app=appliction(window)
window.mainloop()